package com.dqp.cslggroup.UI;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.dqp.cslggroup.R;
import com.dqp.cslggroup.bean.Borrow;

import java.util.List;

/**
 * @author 董琴平
 * @version 1.0
 * @date 2021/9/4 23:11
 */
public class BorrowAdapter extends BaseAdapter {

    private List<Borrow> borrows;
    private LayoutInflater inflater;
    private BorrowAdapter BorrowAdapter;

    public BorrowAdapter(List<Borrow> borrows, Context context) {
        this.borrows = borrows;
        this.inflater = LayoutInflater.from(context);
    }


    public int getCount() {
        return borrows == null ? 0 : borrows.size();
    }


    public Object getItem(int position) {
        return borrows.get(position);
    }


    public long getItemId(int position) {
        return position;
    }


    public View getView(int position, View convertView, ViewGroup parent) {
        @SuppressLint("ViewHolder") View view = inflater.inflate(R.layout.four_textview_item, null);
        Borrow borrow = (Borrow) getItem(position);
        TextView textview_1 = view.findViewById(R.id.textview_1);
        TextView textview_2 = view.findViewById(R.id.textview_2);
        TextView textview_3 = view.findViewById(R.id.textview_3);
        TextView textview_4 = view.findViewById(R.id.textview_4);
        textview_1.setText(borrow.getBookname());
        textview_2.setText(borrow.getBorrowTime() + "");
        textview_3.setText(borrow.getLimitedTime() + "");
        if (Integer.parseInt(borrow.getStatus()) == 0)
            textview_4.setText("未超期");
        if (Integer.parseInt(borrow.getStatus()) == 1)
            textview_4.setText("已超期");
        return view;
    }

}
